import java.io.IOException;
import java.net.ServerSocket;

import javax.swing.JOptionPane;

public class Server extends Thread {
	private ServerSocket serverSocket;
	private int port;

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public void run() {
		try {
			port = Integer.parseInt(JOptionPane.showInputDialog("Enter port number:"));
			serverSocket = new ServerSocket(port);
		} catch (IOException e) {
			System.exit(-1);
		}

		while (true) {
			SocketThread socketThread;
			try {
				// server.accept returns a client connection
				socketThread = new SocketThread(serverSocket.accept());
				socketThread.start();
			} catch (IOException e) {
				System.exit(-1);
			}
		}
	}
	
	public static void main(String[] args) {
		Server server = new Server();
		server.run();
	}
}
